package com.riatimes.net.localconnection
{
	import com.riatimes.util.Logger;
	import com.riatimes.util.SWFBridgeAS3;

	import flash.events.Event;

	import org.puremvc.as3.patterns.observer.Notifier;


	public dynamic class LocalConnectionService extends Notifier
	{
		private var lc:SWFBridgeAS3;
		private static var instance:LocalConnectionService;

		public static function getInstance():LocalConnectionService
		{
			if (instance == null)
				instance=new LocalConnectionService();
			return instance;
		}

		public function LocalConnectionService()
		{
			lc=new SWFBridgeAS3("_coinfacotry3", this);
			lc.addEventListener(Event.CONNECT, onConnect);

		}

		public function send(notificationName:String, body:*):void
		{
			lc.send("getData", notificationName, body);
		}

		private function onConnect(e:Event):void
		{
			Logger.logInfo("localconnection connected!");
		}

		public function getData(notificationName:String, body:*):void
		{
			Logger.logInfo("getData:", notificationName);
			Logger.logObject(body);
			sendNotification(notificationName, body);
		}
	}
}